package com.gastronomy.controller;


import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.gastronomy.entity.DishesEntity;
import com.gastronomy.entity.InformationEntity;
import com.gastronomy.entity.User;
import com.gastronomy.service.DishesService;
import com.gastronomy.service.InformationService;
import com.gastronomy.service.NavService;
import com.gastronomy.service.UserService;

@Controller
@RequestMapping("/foodIndex")
public class FoodController {

	@Resource
	private InformationService informationService;
	@Resource
	private DishesService dishesService;
	@Resource
	private UserService userService;
	
	@RequestMapping("/index")
	public String toIndex(HttpServletRequest request,HttpServletResponse response,Model model){
		System.out.println("-----进入首页");
		//仅显示第一页的两条数据
		List<InformationEntity> resultEntities = informationService.listInformations(1,2);
		model.addAttribute("entities",resultEntities);
		//显示4条推荐的美食信息，按访问量排序
		List<DishesEntity> foodList =  dishesService.sortDishes("B","focuse","","1",4);
		//显示4条推荐的商家信息，按注册时间排序
		List<User> userList =  userService.sortBusiness("B","createTime","","1",4);
		
		model.addAttribute("dishesEntities",foodList);
		model.addAttribute("userEntities",userList);
		return "food/index";
		
	}
	
	
	@RequestMapping("/detail")
	public String informationDetail(HttpServletRequest request,HttpServletResponse response,Model model){
		
		String informationId = request.getParameter("informationId");
		InformationEntity informationEntity = informationService.getInformationById(informationId);
		model.addAttribute("informationEntity",informationEntity);
		
		informationService.updateInformationFocuse(informationEntity);
		return "food/foodDetail";
	}
}
